//
//  LBWMainViewController.swift
//  weibo
//
//  Created by Limonwei on 15/12/5.
//  Copyright © 2015年 heima. All rights reserved.
//

//主视图 根控制器  tababr

import UIKit
import SVProgressHUD

class LBWMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabbar = LBWTabBar()
        
        //闭包
        tabbar.composeButtonClosure = { [weak self] in
            
            
            if !LBWUserAccountViewModel.shareAccount.userLogin {
                SVProgressHUD.showErrorWithStatus("请先登录")
                
                return
            }
            //初始化composeView
            let composeView = LBWComposeView()
            
            composeView.show(self)
            
            
            //printLog(self?.view)
  
        }
        
        //forKeyPath:要用系统的tabBar  LBWTabBar
        setValue(tabbar, forKeyPath: "tabBar")
        
        //设置子控制器
        addChildViewController(LBWHomeTableViewController(), imgName: "tabbar_home", title: "首页")
        
        addChildViewController(LBWMessageTableViewController(), imgName: "tabbar_message_center", title: "消息")
        
        addChildViewController(LBWDiscoverTableViewController(), imgName: "tabbar_discover", title: "发现")
        
        addChildViewController(LBWProfileTableViewController(), imgName: "tabbar_profile", title: "我")
        
        //self.performSelector("dismiss", withObject: nil, afterDelay: 5)
        
 
    }
    
    func dismiss(){
        
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    //添加子控制器
    func addChildViewController(childController: UIViewController, imgName: String, title: String) {
        //
        childController.title = title
        
        childController.tabBarItem.image = UIImage(named: imgName)
        
        //渲染图片以原样显示
        childController.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        //设置title颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        //添加子控制器 用nav控制器把子控制器包起来
       addChildViewController(LBWNavigationController(rootViewController: childController))
        
    }
    
    deinit{
        
        printLog("呵呵")
    }
    
    

   
    

}










